package main

import . "local/algorithm/util"

func rotateList(head *ListNode, k int) *ListNode {
	if head == nil || k == 0 {
		return head
	}
	l := 0
	cur := head
	for cur != nil {
		l++
		cur = cur.Next
	}

	p, q := head, head
	for i := 0; i < k%l; i++ {
		q = q.Next
	}

	for q.Next != nil {
		p = p.Next
		q = q.Next
	}

	q.Next = head
	tmp := p.Next
	p.Next = nil

	return tmp
}

func main() {
	list := GenerateLinkedList([]int{1})
	PrintLinkedList(rotateList(list, 1))
}
